package summit.tests
{
import flash.events.Event;

import summit.basecamp.helpers.PersonHelper;
import summit.data.AccountToken;
import summit.events.BasecampAPIEvent;
import summit.tests.tools.SummitTestContainer;

public class PersonHelperTests extends SummitTestContainer
{
	private var _companyId:String;
	private var _first:Boolean = true;
	
	public function PersonHelperTests(token:AccountToken)
	{
		super(token);
	}
	
	override protected function self_CompleteInit(e:Event):void
	{
		_companyId = this.projectXML.company[0].id;
		super.self_CompleteInit(e);
	}
	
	public function readTest(context:Object):void
	{
		super.initializeLoader(loader_OKRead);
		loader.load(PersonHelper.read(null));
	}
	
	private function loader_OKRead(e:BasecampAPIEvent):void
	{
		super.initializeLoader(loader_OKComplete);
		loader.load(PersonHelper.read(e.data.children()[0].id));
	}
	
	public function listTest(context:Object):void
	{
		super.initializeLoader(loader_OKList);
		loader.load(PersonHelper.list(null));
	}
	
	private function loader_OKList(e:BasecampAPIEvent):void
	{
		if(_first)
		{
			_first = false;
			loader.load(PersonHelper.list(_companyId));
		}
		else
		{
			super.initializeLoader(loader_OKComplete);
			loader.load(PersonHelper.list(_companyId, projectId));
		}
		
	}
	
}
}